#coding=utf-8
import cgi
import model
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
import os,datetime
from google.appengine.ext.webapp import template



class MainPage(webapp.RequestHandler):
  def get(self):
    #pages = db.GqlQuery(r"select * from Page where nextTime <= '" % datetime.datetime.now() % "'Order by date ")
    pages = ""
    path = os.path.join(os.path.dirname(__file__), 'todaypage.html')
    self.response.out.write(template.render(path,pages))

class AddPage(webapp.RequestHandler):
  def get(self):
    self.response.out.write("addpage")

class ViewPage(webapp.RequestHandler):
  def get(self):
    self.response.out.wirte("viewpage")

class Guestbook(webapp.RequestHandler):
  def post(self):
    greeting = Greeting()

    if users.get_current_user():
      greeting.author = users.get_current_user()

    greeting.content = self.request.get('content')
    greeting.put()
    self.redirect('/')

application = webapp.WSGIApplication(
                                     [('/', MainPage),
                                      ('/sign', Guestbook),
                                      ('/add',AddPage),
                                      ('/view',ViewPage)],
                                     debug=True)

def main():
  run_wsgi_app(application)

if __name__ == "__main__":
  main()
